package com.cskaoyan.demo10.bean;

import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;


//用于封装参数
@Data
public class PageParameter {
    private Integer page;
    private Integer limit;
    private String sort;
    private String order;
    private Integer offset; // (page-1)*limit

    public static PageParameter init(Map<String,String[]> parameterMap) {
        PageParameter pageParameter = new PageParameter();
        try {
            BeanUtils.copyProperties(pageParameter, parameterMap);
            //pageParameter.setOffset((pageParameter.getPage() - 1) * pageParameter.getLimit());
            return pageParameter;
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
